package Lock;

import java.util.concurrent.locks.ReentrantLock;
import java.util.concurrent.locks.Lock;

/**
 * Created with IntelliJ IDEA.
 * User: belict
 * Date: 12/1/13
 * Time: 4:32 PM
 * To change this template use File | Settings | File Templates.
 */
public class ReentrantLockDemo {
    Lock lock = new ReentrantLock();
    public void start() throws InterruptedException {
        System.out.println("Before lock Thread#" + Thread.currentThread().getId());

        while(!lock.tryLock()){
            Thread.sleep(100);
   //         System.out.println("Thread # " + Thread.currentThread().getId());
        }

        System.out.println("In lock#1 Thread#" + Thread.currentThread().getId());
        lock.lock();
        System.out.println("In lock#2 Thread#" + Thread.currentThread().getId());
        lock.unlock();


        return;

    }
}
